package com.dundun.SSO.pojo;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.util.List;

/**********************************************************
 * 版权所有：搜影科技 保留所有权利
 * 创建日期: 2017/3/24 0024 11:26
 * 创建作者: gezhangkai
 * 版    本:
 * 功    能:
 * 最后修改时间:
 * 修改记录:
 ***********************************************************/
@Component
public class ResponseBean<T> implements Serializable{
    private Integer code;
    private Object data;
    private String msg;
    private int total;
    private List<T> rows;


    public ResponseBean(){}

    public ResponseBean(Integer code,Object data,String msg){
        this.code = code;
        this.data = data;
        this.msg = msg;
    }

    public static <T>ResponseBean<T> success(String msg,Object data){
        ResponseBean<T> responseBean = new ResponseBean<T>();
        responseBean.setCode(Constant.SUCCESS.getCode());
        responseBean.setMsg(StringUtils.isNotBlank(msg)?msg:Constant.SUCCESS.getMsg());
        responseBean.setData(data);
        return responseBean;
    }

    public static <T>ResponseBean<T> unknowError(String msg,Object data){
        ResponseBean<T> responseBean = new ResponseBean<T>();
        responseBean.setCode(Constant.UNKNOWN_ERROR.getCode());
        responseBean.setMsg(StringUtils.isNotBlank(msg)?msg:Constant.UNKNOWN_ERROR.getMsg());
        responseBean.setData(data);
        return responseBean;
    }

    public static <T>ResponseBean<T> parameterError(String msg){
        ResponseBean<T> responseBean = new ResponseBean<T>();
        responseBean.setCode(Constant.PARAMETER_ERROR.getCode());
        responseBean.setMsg(StringUtils.isNotBlank(msg)?msg:Constant.PARAMETER_ERROR.getMsg());
        return responseBean;
    }

    public static <T>ResponseBean<T> parameterConvertException(String msg){
        ResponseBean<T> responseBean = new ResponseBean<T>();
        responseBean.setCode(Constant.PARAMETER_CONVERT_EXCEPTION.getCode());
        responseBean.setMsg(StringUtils.isNotBlank(msg)?msg:Constant.PARAMETER_CONVERT_EXCEPTION.getMsg());
        return responseBean;
    }


    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public List<T> getRows() {
        return rows;
    }

    public void setRows(List<T> rows) {
        this.rows = rows;
    }
}
